package cn.tsoft.taobao.ui;

import cn.tsoft.taobao.logic.ITaoBaoActivity;
import cn.tsoft.taobao.logic.Task;
import cn.tsoft.taobao.logic.TaskManagerActivity;
import cn.tsoft.taobao.util.AuthorInfo;
import cn.tsoft.taobao.util.LogInInfo;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class LoginActivity extends TaskManagerActivity implements ITaoBaoActivity{
	
	 public static final int REFRESH_LOGIN=1;
	 
	private WebView webView ; 
	
	private ProgressDialog progressDialog = null;
	
	private Button return_button ;
	
	@SuppressWarnings("static-access")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
	     Task task = new  Task(Task.TASK_USER_LOGIN,null);
	     getStuffApplication().addTask(task);
		webView = (WebView)findViewById(R.id.loginView);
		return_button = (Button) findViewById(R.id.return_button) ;
		return_button.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	            	 LogInInfo.getUserSessionKey();
	            	 Intent intent = new Intent(LoginActivity.this, MainActivity.class);
	            	 startActivity(intent);
	            }
	        });
		 progressDialog = ProgressDialog.show(LoginActivity.this, "请稍等...", "记载淘宝官方登录页面中...", true); 
		 getStuffApplication().allActivity.add(this);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	public void init() {

	}

	@SuppressWarnings("static-access")
	@Override
	public void refresh(Object... param) {
	    //得到WebSettings对象，设置支持Javascript的参数   
        webView.getSettings().setJavaScriptEnabled( true );   
        //设置可以支持缩放   
        webView.getSettings().setSupportZoom( true );   
        //设置出现缩放工具   
        webView.getSettings().setBuiltInZoomControls( true );  
        webView.loadUrl( AuthorInfo.getInstance().authorUrl); 
        webView.setWebViewClient( new  WebViewClient(){
			public   boolean  shouldOverrideUrlLoading(WebView view, String url) {          
               view.loadUrl(url);
               progressDialog.dismiss();
               return   true ;          
           }   
        });   
        getStuffApplication().allActivity.remove(this);
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
        //重写返回键
		if (keyCode == KeyEvent.KEYCODE_BACK) {
		//点击返回键时所作的操作
			LogInInfo.getUserSessionKey();
		}
		return super.onKeyDown(keyCode, event);
	}
	
}
